package com.example.lib_base.base.fragment

import android.os.Bundle
import android.widget.Toast
import androidx.databinding.ViewDataBinding
import com.example.lib_base.base.view.LoadDialog
import com.example.lib_base.base.vm.BaseRvViewModel
import com.example.lib_base.base.vm.FlyBaseConstants

abstract class BaseAppFragment<B : ViewDataBinding, VM : BaseRvViewModel> :BaseBVMFragment<B,VM>() {


    override fun initialize(savedInstanceState: Bundle?) {

    }

    override fun showLoadingUI(isShow: Boolean) {
            if (isShow){
                LoadDialog.show(activity)
            }else{
                LoadDialog.dismiss(activity)
            }
    }

    override fun showEmptyUI(isShow: Boolean) {

    }

    override fun showToast(map: Map<String, *>) {

        if (map[FlyBaseConstants.FLY_TOAST_KEY_CONTENT_TYPE] == FlyBaseConstants.FLY_TOAST_CONTENT_TYPE_STR) {
            if (map[FlyBaseConstants.FLY_TOAST_KEY_DURATION] == null) {
                Toast.makeText(
                    activity,
                    map[FlyBaseConstants.FLY_TOAST_KEY_CONTENT] as String,
                    Toast.LENGTH_SHORT
                ).show()
            } else {
                Toast.makeText(
                    activity,
                    map[FlyBaseConstants.FLY_TOAST_KEY_CONTENT] as String,
                    map[FlyBaseConstants.FLY_TOAST_KEY_DURATION] as Int
                ).show()
            }
        } else if (map[FlyBaseConstants.FLY_TOAST_KEY_CONTENT_TYPE] == FlyBaseConstants.FLY_TOAST_CONTENT_TYPE_RESID) {
            if (map[FlyBaseConstants.FLY_TOAST_KEY_DURATION] == null) {
                Toast.makeText(
                    activity,
                    map[FlyBaseConstants.FLY_TOAST_KEY_CONTENT] as Int,
                    Toast.LENGTH_SHORT
                ).show()
            } else {
                Toast.makeText(
                    activity,
                    map[FlyBaseConstants.FLY_TOAST_KEY_CONTENT] as Int,
                    map[FlyBaseConstants.FLY_TOAST_KEY_DURATION] as Int
                ).show()
            }
        }
    }

    override fun navigate(page: Any) {

    }

    override fun backPress(arg: Any?) {

    }

    override fun finishPage(arg: Any?) {

    }

}